package net.lzzy.demomybatis.Controller;

import net.lzzy.demomybatis.entity.Comment;
import net.lzzy.demomybatis.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    CommentService commentService;
    @GetMapping("/")
    public List<Comment> getAllComments() {
        return commentService.getAllComments();
    }

    @PostMapping("/")
    public int addComment(@RequestBody Comment comment) {
        return commentService.addComment(comment);
    }

    @DeleteMapping("/")
    public int deleteCommentById(@PathVariable int id) {
        return commentService.deleteCommentById(id);
    }

    @PutMapping("/")
    public int updateCommentById(@RequestBody Comment comment) {
        return commentService.updateCommentById(comment);
    }
}
